using System;
using System.Collections.Generic;
using System.Text;

using LibrErian.Model;
using LibrErian.Common;
using Microsoft.Practices.CompositeUI;
using LibrErian.Interfaces.Services;

namespace LibrErian.Modules.BasicBook
{
    public class AuthorViewPresenter : Presenter<IAuthorView>
    {
        private Author author;
        private IAuthorService authorService;

        [ServiceDependency]
        public IAuthorService AuthorService
        {
            set
            {
                authorService = value;
            }
        }

        [State]
        public Author Author
        {
            set
            {
                author = value;
            }
        }

        public void Save()
        {
            authorService.Save(author);
        }

        public void OnOk()
        {
            Save();
            this.CloseView();
        }

        public void OnCancel()
        {
            State["Author"] = null;
            this.CloseView();
        }

        public override void OnViewReady()
        {
            base.OnViewReady();

            View.SetAuthor(author);
        }
    }

    public interface IAuthorView
    {
        void SetAuthor(Author author);
    }
}
